package com.zhkc.iess.system.service;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhkc.iess.system.dto.UserDTO;
import com.zhkc.iess.system.entity.User;
import com.zhkc.iess.system.mapper.UserMapper;
import com.zhkc.iess.system.vo.UserDetailsVO;
import com.zhkc.iess.system.vo.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class UserService extends ServiceImpl<UserMapper, User> {


    public void updateInfo(UserDTO dto){
        User user = new User();
        BeanUtil.copyProperties(dto,user);
        this.save(user);
    }

    public List<UserVO> userList(){

        List<User> list = this.query().list();

        List<UserVO> userVOS = BeanUtil.copyToList(list, UserVO.class);
        UserVO vo = userVOS.get(0);
        vo.setUserDateTime(LocalDateTime.now());
        vo.setTestDate(new Date());
        vo.setUserDate(LocalDate.now());
        return userVOS;

    }


    public UserDetailsVO details(){
        List<User> list = this.query().list();

        List<UserDetailsVO> userVOS = BeanUtil.copyToList(list, UserDetailsVO.class);
        return userVOS.get(0);

    }

}




